﻿using GenericHtml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WLFramework.Json;
using WLFramework.Web;

namespace SampleSite.admin.ajax
{
    /// <summary>
    /// getUserRole 的摘要说明
    /// </summary>
    public class getUserRole : AjaxHttpHandler
    {

        public override void OnProcessRequest(HttpContext context)
        {
            int? uid = context.GetValueByName<int?>("U_ID");
            if (uid == null)
                return;

            using (var db = new PermissionContext())
            {
                var userroles = db.View_UserRoles.Where(k => k.U_ID == uid);

                context.Response.Write(JSON.Instance.ToJSON(new
                {
                    total = userroles.Count(),
                    rows = userroles.Select(k => new
                    {
                        U_ID = k.U_ID,
                        R_ID = k.R_ID,
                        R_State = k.R_State,
                        R_CName = k.R_CName,
                        R_EName = k.R_EName,
                        R_Description = k.R_Description
                    }).ToList()
                }));
            }
        }
    }
}